# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=xmonad-extras
pkgver=0.17.0
pkgrel=155
pkgdesc="Third party extensions for xmonad with wacky dependencies"
url="https://github.com/xmonad/xmonad-extras"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-x11' 'haskell-alsa-mixer' 'haskell-hint' 'haskell-libmpd'
         'haskell-network' 'haskell-regex-posix' 'xmonad' 'xmonad-contrib')
makedepends=('ghc')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('9d3a73472f3a65e2760cca25062cd3e96938ec39fe246e13db295c48d0b37c4e')

build() {
  cd $pkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' \
    -f-testing -fwith_brightness -fwith_hint -f-with_hlist -fwith_mpd -fwith_regex_posix -fwith_sound -fwith_template_haskell

  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
  cd $pkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
